package com.qf.microuser.point.service.impl;

import com.qf.common.core.entity.PointInfo;
import com.qf.common.core.utils.UserUtils;
import com.qf.microuser.point.mapper.PointInfoMapper;
import com.qf.microuser.point.service.PointInfoService;
import com.qf.microuser.user.service.UserService;
import groovy.lang.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * 2024/12/30
 */
@Service
public class PointInfoServiceImpl implements PointInfoService {
    @Resource
    private PointInfoMapper pointInfoMapper;

    @Resource
    // 这里使用懒加载，防止循环依赖
    @Lazy
    private UserService userService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addPointInfo(PointInfo pointInfo) {
        pointInfoMapper.insert(pointInfo);
        Integer uid = UserUtils.getUid();
        userService.updatePoint(uid, pointInfo.getPoint());
    }
}
